package com.jinzheng.kafkacom.listener;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

/**
 * kafka消费者
 */
@Component
@Slf4j
public class TopicComponent {

    @KafkaListener(topics = {"tesdsea"},groupId = "{spring.kafka.groupid:jinzheng_kakfa_value}")
    public void handMessage(ConsumerRecord<String, String> record ,@Header("header_name") String headername){
        String topic = record.topic();
        String msg = record.value();
        log.info("消费者接受消息：topic-->"+topic+",msg->>"+msg+",header_name->>"+headername);
//        try {
//            acknowledgment.acknowledge();
//        }catch (Exception ex){
//            log.error("解析提取数据发生错误："+ex.getMessage(),ex);
//        }
    }
}

